package makabakaquestionnaire.zutsoftware.framework.security.handle;

import com.alibaba.fastjson.JSON;
import makabakaquestionnaire.zutsoftware.constant.HttpStatus;
import makabakaquestionnaire.zutsoftware.constant.Result;
import makabakaquestionnaire.zutsoftware.utils.ServletUtils;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.Serializable;

/**
 * @author ：wjf
 * @date ：Created in 2022/2/20 12:39
 * @description：登陆失败处理类
 * @modified By：
 */
@Component
public class LoginFailHandlerImpl implements AuthenticationEntryPoint, Serializable
{
    private static final long serialVersionUID = -8970718410437077606L;

    @Override
    public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {
        int code= HttpStatus.SIGN_FAIL_CODE;
        ServletUtils.renderString(httpServletResponse, JSON.toJSONString(Result.restResult("登陆失败",code,"用户名或者密码错误")));
    }
}
